package com.itheima.springbootwebtlias.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Slf4j
@Component
//1.自定义拦截器类:实现HandlerInterceptor接口
public class MyInterceptor implements HandlerInterceptor {
    //2.重写方法

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("拦截器，拦截前... ...");
        //1.登录验证，权限验证，敏感数据检测，字符编码统一处理

        //2.放行 不放行
        return true;//true放行，false不放行
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("拦截器，拦截后... ...");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("拦截器，拦截后2... ...");
    }
}
